package jp.tonosama.komoki.SimpleGolfScorer2.history;

import jp.tonosama.komoki.SimpleGolfScorer2.R;
import jp.tonosama.komoki.SimpleGolfScorer2.Util;
import jp.tonosama.komoki.SimpleGolfScorer2.data.GolfScoreData;
import android.content.Context;
import android.util.Log;

/**
 * @author Komoki
 */
public class GolfScoreManager {

    /**  */
    private static final String TAG = GolfScoreManager.class.getSimpleName();
    /**  */
    public static final boolean DEBUG = false;
    /**  */
    private int mSavedNum;
    /**  */
    private int[] mPlayerNum;
    /**  */
    private int[] mPrefNumber;
    /**  */
    private GolfScoreData[] mScoreDataList;

    /**
     * コンストラクタ
     * 
     * @param context
     * @param savedDataNum
     * @param maxPlayerNum
     */
    public GolfScoreManager(final Context context, final int savedDataNum, final int maxPlayerNum) {

        mPlayerNum = new int[savedDataNum];
        mPrefNumber = new int[savedDataNum];

        mScoreDataList = new GolfScoreData[savedDataNum];
        for (int idx = 0; idx < savedDataNum; idx++) {
            mScoreDataList[idx] = Util.loadScoreDataFromPref(context, idx);
        }
        if (GolfScoreManager.DEBUG) {
            Log.d(TAG, "new instance created.");
        }
    }

    public void setSavedNum(final int savedNum) {
        mSavedNum = savedNum;
    }

    public int getSavedNum() {
        return mSavedNum;
    }

    public void setPlayerNum(final int saveNum, final int playerNum) {
        mPlayerNum[saveNum] = playerNum;
    }

    public int getPlayerNum(final int saveNum) {
        return mPlayerNum[saveNum];
    }

    public void setHoleTitle(final int saveNum, final String holeTitle) {
        mScoreDataList[saveNum].setHoleTitle(holeTitle);
    }

    public String getHoleTitle(final int saveNum) {
        return mScoreDataList[saveNum].getHoleTitle();
    }

    public void setPlayerNames(final int saveNum, final String[] playerNames) {
        mScoreDataList[saveNum].setNames(playerNames);
    }

    public String[] getPlayerNames(final int saveNum) {
        return mScoreDataList[saveNum].getNames();
    }

    public void setWeather(final int saveNum, final int roundCondit) {
        mScoreDataList[saveNum].setCondition(roundCondit);
    }

    public int getWeather(final int saveNum) {
        return mScoreDataList[saveNum].getCondition();
    }

    public int getWeatherImageResourceId(final int saveNum) {
        int[] weather = { R.drawable.weather_shine, R.drawable.weather_cloudy,
                R.drawable.weather_rain, R.drawable.weather_wind, R.drawable.weather_mud, };
        return weather[mScoreDataList[saveNum].getCondition()];
    }

    public void setAllParValues(final int saveNum, final int[] allPar) {
        mScoreDataList[saveNum].setEachHolePar(allPar);
    }

    public int[] getAllParValues(final int saveNum) {
        return mScoreDataList[saveNum].getEachHolePar();
    }

    public void setMyPatting(final int saveNum, final int[] myPatting) {
        mScoreDataList[saveNum].setAbsolutePatting(myPatting);
    }

    public int[] getMyPatting(final int saveNum) {
        return mScoreDataList[saveNum].getAbsolutePatting()[0];
    }

    public void setHandiCaps(final int saveNum, final int[] handicaps) {
        mScoreDataList[saveNum].setPlayersHandi(handicaps);
    }

    public int[] getHandiCaps(final int saveNum) {
        return mScoreDataList[saveNum].getPlayersHandi();
    }

    public void setPrefNumber(final int saveNum, final int prefNumber) {
        mPrefNumber[saveNum] = prefNumber;
    }

    public int getPrefNumber(final int saveNum) {
        return mPrefNumber[saveNum];
    }

    public int[] getPlayersHandi(final int saveNum) {
        return mScoreDataList[saveNum].getPlayersHandi();
    }

    public void setAllScores(final int saveNum, final int[][] allScores) {
        mScoreDataList[saveNum].setAbsoluteScore(allScores);
    }

    public int[][] getAllScores(final int saveNum) {
        return mScoreDataList[saveNum].getAbsoluteScore();
    }
}